package com.cartel.genius.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * Persistence Entity Class for Places 
 * 
 * @author Naresh Reddy
 */
@Entity
@Table (name = "PLACE", uniqueConstraints = @UniqueConstraint(columnNames = {"PLACECODE"}))
public class PlaceEntity implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "PLACEID")
	private int placeId;
	
	@Column(name = "PLACENAME", length = 80, nullable = false)
	private String placeName;
	
	@Column(name = "PLACECODE", length = 10, nullable = false)
	private String placeCode;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "CATEGORYID", nullable = false)
	private CategoryEntity category;
	
	@ManyToOne
	@JoinColumn(name = "PARENTPLACEID", nullable = true)
	private PlaceEntity parent;
	
	@Column(name = "STATUS", length = 1, nullable = false)
	private int status = 1;
	
	@Column(name = "CREATEDDATE", nullable = false)
	private long createdDate;
	
	@Column(name = "MODIFIEDDATE", nullable = false)
	private long modifiedDate;

	public int getPlaceId() {
		return placeId;
	}

	public void setPlaceId(int placeId) {
		this.placeId = placeId;
	}

	public String getPlaceName() {
		return placeName;
	}

	public void setPlaceName(String placeName) {
		this.placeName = placeName;
	}

	public String getPlaceCode() {
		return placeCode;
	}

	public void setPlaceCode(String placeCode) {
		this.placeCode = placeCode;
	}

	public CategoryEntity getCategory() {
		return category;
	}

	public void setCategory(CategoryEntity category) {
		this.category = category;
	}

	public PlaceEntity getParent() {
		return parent;
	}

	public void setParent(PlaceEntity parent) {
		this.parent = parent;
	}	

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}	

	public long getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(long createdDate) {
		this.createdDate = createdDate;
	}

	public long getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(long modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((placeCode == null) ? 0 : placeCode.hashCode());
		result = prime * result + placeId;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		PlaceEntity other = (PlaceEntity) obj;
		if (placeCode == null) {
			if (other.placeCode != null) {
				return false;
			}
		} else if (!placeCode.equals(other.placeCode)) {
			return false;
		}
		if (placeId != other.placeId) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "PlaceEntity [placeId=" + placeId + ", placeName=" + placeName + ", placeCode=" + placeCode + ", category=" + category + ", parent=" + parent + "]";
	}	

}
